package com.web.shop.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.web.shop.pojo.*;
import com.web.shop.service.TypeTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("/typeTemplate-Ms")
public class TypeTemplateController {

	@Autowired
	private TypeTemplateService typeTemplateService;

	@RequestMapping("/findAllbrand")
	public List<TbBrand> querybrand(){
		return typeTemplateService.findAllbrand();
	}

	@RequestMapping("/findAll")
	public List<TbTypeTemplate> findAll(){
		return typeTemplateService.findAll();
	}

	@RequestMapping("/update")
	public RespBean update(@RequestBody TbTypeTemplate typeTemplate){
			typeTemplateService.update(typeTemplate);
			return RespBean.ok("修改成功");
	}	

	@RequestMapping("/findOne")
	public TbTypeTemplate findOne( Long id){
		return typeTemplateService.findOne(id);		
	}
	

	@RequestMapping("/delete/{id}")
	public RespBean delete(@PathVariable Long id){
			typeTemplateService.delete(id);
			return RespBean.ok("删除成功");
	}
	//查询+分页
	@GetMapping("/listByPage")
	public PageResp<TbTypeTemplate> listByPage(PageReq pageReq) {
		PageHelper.startPage(pageReq.getPage(),pageReq.getSize());
		Page<TbTypeTemplate> page = (Page<TbTypeTemplate>) typeTemplateService.findAll();
		PageResp pageResp = new PageResp();
		pageResp.setList(page.getResult());
		pageResp.setTotal(page.getTotal());
		return pageResp;
	}
	
//	@RequestMapping("/findBySpecList")
//	public List<Map> findSpecList(Long id){
//		return typeTemplateService.findSpecList(id);
//	}
	
	
}
